// ============================== 导入依赖 ============================== //

import API from './API'
import ENTRANCE_API from './entrance/API'
import AREA_API from './area/API'

// ============================== 导出异步调用 ============================== //

export default {
  // —————————————————————————————— 单项 —————————————————————————————— //

  async remoteOne({ state: { one }, commit }) {
    if (!one.id) return {}

    if (one.type === 1) {
      const { parkDto = {}, entranceDto: arr = [] } = await API.getOne(one)
      arr.forEach((item) => (item.oldAreaId = item.areaId))
      commit(['entrance/completeList'], [arr.length, arr])
      return { ...one, parkDto }
    } else {
      const { entrance = {}, content: arr = [] } = await ENTRANCE_API.getOne(one)
      arr.forEach((item) => (item.areaId = entrance.areaId))
      commit(['roadway/completeList'], [arr.length, arr])
      return { ...one, entrance }
    }
  },

  // —————————————————————————————— 增 —————————————————————————————— //

  async remoteAdd({ state: { one } }) {
    const msg = await API.add(one)
    return msg
  },

  // —————————————————————————————— 改 —————————————————————————————— //

  async remoteEdit({ state: { one } }) {
    const msg = await API.edit(one.parkDto)
    return msg
  },

  // —————————————————————————————— 删 —————————————————————————————— //

  async remoteDel({ state: { one } }) {
    const msg = await API.del(one.parkDto)
    return msg
  },

  // —————————————————————————————— 提交 —————————————————————————————— //

  async remoteSubmit() {
    const msg = await AREA_API.submit()
    return msg
  },
}
